<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/3/8
  Time: 13:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>智能锁注册</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="viewport"
	content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
	 <link href="${pageContext.request.contextPath}/static/css/KeysManager/LArea.css" rel="stylesheet">
	<link href="${pageContext.request.contextPath}/static/css/KeysManager/AddLock.css?date=0120" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer_mobile/need/layer.css" rel="stylesheet">
    
    <script rel="script" src="${pageContext.request.contextPath}/static/js/KeysManager/index.js?sate=2"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer_mobile/layer.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/js/KeysManager/VerifyCode.js?date=0119.1"></script>
    <script src="${pageContext.request.contextPath}/static/js/KeysManager/LArea/LAreaData1.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/KeysManager/LArea/LAreaData2.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/KeysManager/LArea/LArea.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/yahlj-app.js"></script>
    
    <link href="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/css/mobiscroll.scroller.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/css/mobiscroll.scroller.android-ics.css" rel="stylesheet">
    
    
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/zepto.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/mobiscroll.zepto.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/mobiscroll.core.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/mobiscroll.scroller.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/mobiscroll.area.js?v=3"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/mobiscroll.scroller.android-ics.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/Mobiscroll-City-master/js/i18n/mobiscroll.i18n.zh.js"></script>
    
    <style type="text/css">
        input{
            box-sizing: content-box;
        }
      </style>
</head>
<body>
<div class="title">
    	<img class="scan" onclick="scanclick()" src="${pageContext.request.contextPath}/static/images/KeysManager/scan.png"/>
    	<p class="scan-info">扫码自动输入PID输入、激活码</p>
</div>
<form id="uploadForm">
            <input type="hidden" name="type" id="type" value="${type}" />
            <input type="hidden" name="typeAPP" id="typeAPP" value="0">
    <div class="content">

        <div class="item">

            <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/PID.png"/>

            <input type="text" name="pid" id="pid" class="edittext" placeholder="请输入PID" value="${pid }"/>

        </div>

        <div class="item">

            <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/activationCode.png"/>

            <input type="text" name="checkCode" id="checkCode" class="edittext" placeholder="请输入激活码" value="${checkcode}"/>

        </div>

        <div class="item">

            <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/editName.png"/>

            <input type="text" name="communityName" id="communityName" class="edittext" placeholder="请输入姓名"/>

        </div>

        <div class="item">

            <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/key.png"/>

            <input type="text" name="lockName" id="lockName" class="edittext" placeholder="请输入智能锁名称(10个字以内)"/>

        </div>

        <div class="item">

            <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/address.png"/>

            <!--<input type="text" name="address" id="address" class="" placeholder="请选择"/>-->

            <div class="content-block">
                <input id="demo2" type="text" readonly="" class="edittext" placeholder="城市选择" areaid="" />
                <input id="value2" type="hidden" />
            </div>

        </div>
        <div class="item">
            <input type="text" name="street" id="street" class="edittext" placeholder="请输入详细地址"/>
        </div>
    </div>
    <div class="item">
        <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/telephone.png"/>
        <input type="text" class="edittext" name="tel" id="tel" value="${tel}" placeholder="请输入绑定手机号"/>
    </div>

    <div class="verifty">
            <img class="icon" src="${pageContext.request.contextPath}/static/images/KeysManager/verification.png"/>
            <input type="text" class="inputVerify" name="yzm" id="yzm" placeholder="请输入验证码"/>
    </div>
</form>
    <button class="get-verify" id="send">发送验证码</button>

    <div class="foot">
         <button type="submit" name="enter"  id="submit" onclick="doUpload()">确认</button>
    </div>

<script>
	/* var area2 = new LArea();
	area2.init({
		'trigger': '#demo2',
		'valueTo': '#value2',
		'keys': {
			id: 'value',
			name: 'text'
		},
		'type': 2,
		'data': [provs_data, citys_data, dists_data]
	}); */
	var valo = $("#demo2").attr("areaid");
	$('#demo2').scroller('destroy').scroller({ preset: 'area', theme: 'android-ics light', display: 'bottom',valueo:valo });
	
	
function locationReplace(url){
	  if(history.replaceState){
	    history.replaceState(null, document.title, url);
	    history.go(0);
	  }else{
	    location.replace(url);
	  }
}
	
	
	function scanclick(){
		hljJs.scanCode({
			success:function(res){
				
			},
			fail:function(res){
				layer.open({
	        	    content: res,
	        	    btn: '我知道了'
	        	  });
			}
		});
	}
	function callbackScanCode(result){
	  	if(result.code==1){
			var resultStr = result.resultStr;
			if(resultStr.indexOf("?p=")<0){
				layer.open({
		    	    content: "无法获取PID，请重试",
		    	    btn: '我知道了'
		    	  });
		    	  return;
			}
			if(resultStr.indexOf("&c=")<0){
				layer.open({
		    	    content: "无法获取激活码，请重试",
		    	    btn: '我知道了'
		    	  });
				 return;
			}
			var arr1 = resultStr.split("?p=");
			var arr2 = arr1[1].split("&c=");
			var arr3 = arr2[1].split("&v=");
			$("#pid").val(arr2[0]);
			$("#checkCode").val(arr3[0]);
			layer.open({
			    content: '扫描成功'
			    ,skin: 'msg'
			    ,time: 2 //2秒后自动关闭
			  });
		}else if(result.code==2){
		}else{
			layer.open({
	    	    content: "获取二维码扫描结果失败，请重试",
	    	    btn: '我知道了'
	    	  });
		} 
	}
	function doUpload(){
		$("#submit").attr("disabled", "true");
		var pid = $("#pid").val();
		var checkCode = $("#checkCode").val();
	    var communityName = $("#communityName").val();
	    var lockName = $("#lockName").val();
	    var type = $("#type").val();
        var areaCode = $("#demo2").attr("areaid");
        if(!areaCode){
	    	layerAlert("所属区域必填");
	    	 $("#submit").removeAttr("disabled");
	    	 return;
	    }
        var areaCodeArr = areaCode.split(" ");
	    areaCode = areaCodeArr[areaCodeArr.length-1];
	    var street = $("#street").val();
		var departTel = $("#tel").val();
	    var yzm = $("#yzm").val();
	    if(!pid){
	    	 layerAlert("购买锁的PID必填");
	    	 $("#submit").removeAttr("disabled");
	    	 return;
	    }
	    if(!checkCode){
	    	 $("#submit").removeAttr("disabled");
	    	layerAlert("锁的激活码信息必填");
	    	 return;
	    }
	    if(!communityName){
	    	 layerAlert("姓名必填");
	    	 $("#submit").removeAttr("disabled");
	    	 return;
	    }
	    if(!lockName || lockName.length>10){
	    	layerAlert("智能锁名称在10字以内");
	    	 $("#submit").removeAttr("disabled");
	    	 return;
	    }
	    if(!areaCode){
	    	layerAlert("所属区域必填");
	    	 $("#submit").removeAttr("disabled");
	    	 return;
	    }
	    var areaCodeArr = areaCode.split(",");
	    areaCode = areaCodeArr[areaCodeArr.length-1];
	    if(!departTel){
	    	layerAlert("手机号必填");
	    	 $("#submit").removeAttr("disabled");
	    	 return;
	    }else if(!(/^1[3|4|5|7|8]\d{9}$/.test(departTel))){ 
	    	layerAlert("用户手机号有误，请填写有效手机号"); 
	        $("#submit").removeAttr("disabled");
	        return; 
	    }
	    
	    if(!yzm){
	    	layerAlert("验证码必填");
	    	$("#submit").removeAttr("disabled");
	    	return;
	    }else if(!(/^\d{6}$/.test(yzm))){
	    	layerAlert("验证码有误，请填写6位有效数字"); 
	    	$("#submit").removeAttr("disabled");
		    return; 
		}
	    $.post("${pageContext.request.contextPath}/register/tComuLockAdd.action", {
	    	'typeAPP': '0',
		    'pid': pid,
		    'checkCode': checkCode,
		    'communityName': communityName,
		    'lockName': lockName,
	        'areaCode': areaCode,
		    'street': street,
	    	'departTel': departTel,
	    	'yzm': yzm,
	    	'type': type
         }, function (result) {
             result = JSON.parse(result)
             if (result.code == 1) {
            	 locationReplace("${pageContext.request.contextPath}/admin/loginByApp.action");
             }else{
            	 $("#submit").removeAttr("disabled");
            	 layerAlert(result.msg);
             }
         });
	}
	function layerAlert(msg){
		layer.open({
      	    content: msg,
      	    btn: '我知道了'
      	});
	}
</script>
</body>
</html>
